package com.jy.adscm.operation.mscyb.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqbzMaterialList;
import com.jy.adscm.operation.mscyb.bean.JqbzMaterialListCheck;
import com.jy.adscm.operation.mscyb.bean.JqylMaterialdetail;
import com.jy.adscm.operation.mscyb.bean.MaterialCheck;
import com.jy.adscm.operation.mscyb.service.JqylMaterialdetailService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2018-11-29
 */
@RestController
@RequestMapping("/adscm/operation/jqylMaterialdetail")
public class JqylMaterialdetailController {
    @Autowired
    JqylMaterialdetailService jqylMaterialdetailService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JqylMaterialdetail jqylMaterialdetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        jqylMaterialdetail.setOutstoragetime(new Date());
        jqylMaterialdetail.setCreator(token.getUser().getId().toString());
        jqylMaterialdetail.setUseperson(token.getUser().getId().toString());
        boolean insert = jqylMaterialdetailService.insertJqylMaterialdetail(jqylMaterialdetail,token);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("jqylMaterialdetailToShylMaterial")
    public SimpleCoreResponse jqylMaterialdetailToShylMaterial(@RequestBody JqylMaterialdetail jqylMaterialdetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = jqylMaterialdetailService.jqylMaterialdetailToShylMaterial(jqylMaterialdetail,token);
        return new SimpleCoreResponse("200","新增成功",insert);
    }

    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id)throws AdscmSystemException {
        boolean result = jqylMaterialdetailService.deleteById(id);
        return new  SimpleCoreResponse("200","删除成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JqylMaterialdetail jqylMaterialdetail, HttpServletRequest request) throws AdscmSystemException{
        Boolean result = jqylMaterialdetailService.updateLjzzPartsmadedetail(jqylMaterialdetail);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectByTid/{tid}")
    public  SimpleCoreResponse  selectByTid(@PathVariable String tid) throws  AdscmSystemException{
        List<JqylMaterialdetail> JqylMaterialdetails=new ArrayList<>();
        JqylMaterialdetails  = jqylMaterialdetailService.selectByTid(tid);
        return  new SimpleCoreResponse("200","查询成功",JqylMaterialdetails);
    }
    @RequestMapping("selectUnqualifiedMaterial")
    public  SimpleCoreResponse  selectUnqualifiedMaterial() throws  AdscmSystemException{
        List<JqylMaterialdetail> JqylMaterialdetails=new ArrayList<>();
        JqylMaterialdetails  = jqylMaterialdetailService.selectUnqualifiedMaterial();
        return  new SimpleCoreResponse("200","查询成功",JqylMaterialdetails);
    }

    @RequestMapping("selectUnqualifiedMaterialCheck/{id}")
    public  SimpleCoreResponse  selectUnqualifiedMaterialCheck(@PathVariable String id) throws  AdscmSystemException{

        MaterialCheck materialCheck = jqylMaterialdetailService.selectUnqualifiedMaterialCheck(id);
        return  new SimpleCoreResponse("200","查询成功",materialCheck);
    }
    @RequestMapping("selectUnDeal")
    public  SimpleCoreResponse  selectUnDeal(HttpServletRequest request) throws  AdscmSystemException{

        List<JqylMaterialdetail>  jqylMaterialdetails= jqylMaterialdetailService.selectUnDeal();
        return  new SimpleCoreResponse("200","查询成功",jqylMaterialdetails);
    }

    @RequestMapping("selectDeal")
    public  SimpleCoreResponse  selectDeal(HttpServletRequest request) throws  AdscmSystemException{

        List<JqylMaterialdetail>  jqylMaterialdetails= jqylMaterialdetailService.selectDeal();
        return  new SimpleCoreResponse("200","查询成功",jqylMaterialdetails);
    }
    @RequestMapping("updateUnqualified")
    public  SimpleCoreResponse  updateUnqualified(@RequestBody JqylMaterialdetail jqylMaterialdetail,HttpServletRequest request) throws  AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        jqylMaterialdetail.setCreator(token.getUser().getId().toString());
        jqylMaterialdetail.setCreaeTime(new Date());
        Boolean result =jqylMaterialdetailService.updateUnqualified(jqylMaterialdetail);
        return  new SimpleCoreResponse("200","查询成功",result);
    }


}

